Conditions | 8 |
Total Lines | 54 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | /*eslint max-len: ["error", { "code": 150 }]*/ |
||
97 | initMonth() { |
||
98 | let current = this.state.date, |
||
99 | selectedMonth = current.getMonth(), |
||
100 | selectedYear = current.getFullYear(), |
||
101 | currentMonth = utils.getMonthSetup(selectedYear, selectedMonth), |
||
102 | startDay = utils.getDayPos(currentMonth.start), |
||
103 | endDay = currentMonth.end, |
||
104 | day, |
||
105 | week, |
||
106 | weeks = { |
||
107 | 1: [], |
||
108 | 2: [], |
||
109 | 3: [], |
||
110 | 4: [], |
||
111 | 5: [], |
||
112 | 6: [] |
||
113 | }; |
||
114 | |||
115 | for (let i = 0; i < startDay; i++) { |
||
116 | weeks[1].push(<td className="dates empty"></td>); |
||
117 | } |
||
118 | for (day = 1; day <= (7 - startDay); day++) { |
||
119 | let currentDate = this.state.date; |
||
120 | |||
121 | currentDate.setDate(day); |
||
122 | let dateSting = utils.getDateAsString(currentDate); |
||
123 | |||
124 | if (utils.isToday(currentDate)) { |
||
125 | weeks[1].push(<td className="dates today" onClick={() => this.selectDate(dateSting)}>{currentDate.getDate()}</td>); |
||
126 | } else { |
||
127 | weeks[1].push(<td className="dates" onClick={() => this.selectDate(dateSting)}>{currentDate.getDate()}</td>); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | for (week = 2; week <= 6; week++) { |
||
132 | for (let i = 1; i <= 7; i++) { |
||
133 | if (day <= endDay) { |
||
134 | let currentDate = this.state.date; |
||
135 | |||
136 | currentDate.setDate(day); |
||
137 | let dateSting = utils.getDateAsString(currentDate); |
||
138 | |||
139 | if (utils.isToday(currentDate)) { |
||
140 | weeks[week].push(<td className="dates today" onClick={() => this.selectDate(dateSting)}>{currentDate.getDate()}</td>); |
||
141 | } else { |
||
142 | weeks[week].push(<td className="dates" onClick={() => this.selectDate(dateSting)}>{currentDate.getDate()}</td>); |
||
143 | } |
||
144 | } else { |
||
145 | weeks[week].push(<td className="dates empty"></td>); |
||
146 | } |
||
147 | day++; |
||
148 | } |
||
149 | } |
||
150 | return weeks; |
||
151 | } |
||
192 |